package com.mycompany.user.controller;

import com.mycompany.mvc.utils.EasyResult;
import com.mycompany.mvc.utils.RequestUtil;
import com.mycompany.mvc.utils.SystemUtil;
import com.mycompany.tableOpe.entity.TableOpeBean;
import com.mycompany.tableOpe.service.TableOpeService;
import com.mycompany.user.entity.Permission;
import com.mycompany.user.entity.User;
import com.mycompany.user.service.UserService;
import javafx.scene.control.Tab;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Jintao_Ma on 2017/9/2.
 */
@Controller
@RequestMapping("/hangkong")
public class HangkongAction {

    @Autowired
    private UserService userService;

    @Autowired
    private TableOpeService tableOpeService;

    /**
     * 系统左侧菜单栏
     * @param
     * @return
     */
    @RequestMapping("/getAllPermission")
    @ResponseBody
    public List<Permission> getAllPermission(){
        return userService.getAllPermission(new HashMap<String,Object>());
    }

    /**
     * 安全管理菜单跳转
     * @param
     * @return
     */
    @RequestMapping("/getSafeItem")
    @ResponseBody
    public ModelAndView getSafeItem(){
        return tableOpeService.getSafeItem(new HashMap<String,Object>());
    }

    /**
     * 安全管理菜单List
     * @param
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public EasyResult list(HttpServletRequest request){
        Map<String, Object> paraMap = RequestUtil.getReqest(request);
        return tableOpeService.getTableList(paraMap);
    }

    /**
     * 安全管理菜单编辑页
     * @param
     * @return
     */
    @RequestMapping("/toEdit")
    @ResponseBody
    public ModelAndView toEdit(@RequestParam(value = "id", required = true) int id){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        return tableOpeService.editTableList(map);
    }

    /**
     * 安全管理菜单提交
     * @param
     * @return
     */
    @RequestMapping("/edit")
    @ResponseBody
    public EasyResult edit(HttpServletRequest request, TableOpeBean tableOpeBean){
        return tableOpeService.saveTable(tableOpeBean);
    }
}
